package com.zhanggm.springcloud.student.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

@Data
@Entity
@Table(name = "stu_student")
public class StudentEntiy implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private Long classesId;
    private Date createTime;

    private String imageUrl;
    private Long proviceId;
    private Long cityId;
    private Long areaId;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date birthday;

    @Transient
    private String classesName;
    @Transient
    private List<Long> hobbyIdList;




    @OneToOne
    @JoinColumn(name = "proviceId",insertable = false,updatable = false)
    private AreaEntiy provice;

    @OneToOne
    @JoinColumn(name = "cityId",insertable = false,updatable = false)
    private AreaEntiy city;

    @OneToOne
    @JoinColumn(name = "areaId",insertable = false,updatable = false)
    private AreaEntiy area;

    /**
     * 选中的省市区
     * @return
     */
    public List<Long> getSelectAreaList(){
        List<Long> list = new LinkedList<>();
        list.add(this.getProviceId());
        list.add(this.getCityId());
        list.add(this.getAreaId());
        return list;
    }

    @ManyToMany
    @JoinTable(name = "stu_sudent_hobby_relation",joinColumns = @JoinColumn(name = "studentId"),
    inverseJoinColumns = @JoinColumn(name ="hobbyId"))
    private List<HobbyEntiy> hobbyList;

    @OneToMany
    @JoinColumn(name = "pid",referencedColumnName = "proviceId",insertable = false,updatable = false)
    private List<AreaEntiy> cityList;

    @OneToMany
    @JoinColumn(name = "pid",referencedColumnName = "cityId",insertable = false,updatable = false)
    private List<AreaEntiy> areaList;

    @JsonIgnoreProperties("studentList")
    @ManyToOne
    @JoinColumn(name = "classesId",insertable = false,updatable = false)
    private ClassesEntiy classes;



}
